package com.ll.gulimallgateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GuliMallCorsConfiguration {


    @Bean
    public CorsWebFilter corsWebFilter() {
        //开始配置跨域配置
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        //注册跨域配置  任意路径/**
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //所有请求头
        corsConfiguration.addAllowedHeader("*");
        //所有方法
        corsConfiguration.addAllowedMethod("*");
        //任意请求来源
        corsConfiguration.addAllowedOrigin("*");
        //允许cookie跨域
        corsConfiguration.setAllowCredentials(true);
        source.registerCorsConfiguration("/**", corsConfiguration);


        return new CorsWebFilter(source);
    }
}
